import { dictttpRequestFun } from '@/utils/http';
import { getApiUrl, jsonToUrlParam } from '@/utils/urlSearchParams';
import type { DictItemCreateDto, DictItemDto, DictItemUpdateDto, GetDictItemInput } from './type';
import type { PagedResultDto } from '../../type';

const request = dictttpRequestFun();

// Api地址
enum API {
    DEFAULT_URL = 'api/dict/item'
}

// 列表接口
export const getListAsync = (input: GetDictItemInput) => {
    const paramenter = jsonToUrlParam(input);
    const url = getApiUrl(API.DEFAULT_URL, paramenter);
    return request.get<PagedResultDto<DictItemDto>>(url);
};

// 创建
export const createAsync = (input: DictItemCreateDto) =>
    request.post<DictItemDto, DictItemCreateDto>(API.DEFAULT_URL, input);

// 更新
export const updateAsync = (id: string, input: DictItemUpdateDto) =>
    request.put<DictItemDto, DictItemUpdateDto>(`${API.DEFAULT_URL}/${id}`, input);

// 删除
export const deleteAsync = (id: string) => request.delete<boolean>(`${API.DEFAULT_URL}/${id}`);

// 详情
export const getAsync = (id: string) => request.get<DictItemDto>(`${API.DEFAULT_URL}/${id}`);